# -*- coding:utf-8 -*-

# @Time : 2022/11/22 15:11
# @Author : 快乐的小猴子
# @Version : 
# @Function : 
from YouMeiPics.conf import settings
from YouMeiPics.PubBases import PublicBases
from YouMeiPics.MeiNvTuPian.XingGanGirls import XingGanGirls  # 性感美女
from YouMeiPics.MeiNvTuPian.SiWaGirls import SiWaGirls  # 丝袜美女
from YouMeiPics.MeiNvTuPian.MeiNvXieZhen import MeiNvXieZhen  # 美女写真
from YouMeiPics.MeiNvTuPian.WaiGuoMeiNv import WaiGuoGirls  # 外国美女
from YouMeiPics.MeiNvTuPian.NeiYiMeiNv import NeiYiGirls  # 内衣美女
from YouMeiPics.MeiNvTuPian.JiePaiMeiNv import JiePaiGirls  # 街拍美女
from YouMeiPics.MeiNvTuPian.ZiPaiMeiNv import ZiPaiGirls  # 自拍美女
from YouMeiPics.MeiNvTuPian.BodyYiShu import BodyYiShu  # 人体艺术
from YouMeiPics.MeiNvTuPian.GirlsModel import GirlsModel  # 美女模特


class MeiNvTuPian:
    """
    主逻辑类
    """

    def if_levl(self, data_list):
        '''
        判断是否为子1级数据，否则为子2级数据
        :param data_list:
        :return:
        '''
        sec_datas = []
        thr_datas = []
        for data in data_list:
            if data[0] == '1':
                sec_datas.append(data[1])
            else:
                thr_datas.append(data[1])
        return sec_datas, thr_datas

    def get_fir_view_cont(self, sec_datas):
        '''
        获取子一级展示数据信息，即向用户展示的第一级数据
        :param sec_datas:
        :return:
        '''
        show_contents1 = ''
        num_list1 = []
        for i in range(0, len(sec_datas)):
            # 处理展示的第一级字符串提示信息
            pic_type_name = list(sec_datas[i].values())[0][0]
            show_cont1 = str(list(sec_datas[i].keys())[0]) + '\t' + str(pic_type_name) + '\n'
            show_contents1 += show_cont1
            # 对应的序号放入列表，判断用户输入的序号对应的数据是否存在
            num_list1.append(str(list(sec_datas[i].keys())[0]))
        return show_contents1, num_list1

    def get_pic_nm_url(self, temp_cont2_list, in_seq2):
        '''
        获取图片的标题和url地址信息
        :param temp_cont2_list:
        :param in_seq2:
        :return:
        '''
        for k in range(0, len(temp_cont2_list)):
            if in_seq2 != list(temp_cont2_list[k].keys())[0]:
                continue
            else:
                pic_name = temp_cont2_list[k][in_seq2][0]
                pic_url = temp_cont2_list[k][in_seq2][1]
                return pic_name, pic_url

    def handle_rela(self, in_seq, thr_datas):
        '''
        处理获取到的数据，拼接二级展示数据字符串
        :param in_seq:
        :param thr_datas:
        :return:
        '''
        show_contents2 = ''
        num_list2 = []
        temp_cont2_list = []
        for j in settings.rel_list[int(in_seq)]:
            show_cont2 = str(j) + '\t' + str(thr_datas[j - 1]) + '\n'
            # print(show_cont2)
            show_contents2 += show_cont2
            num_list2.append(j)
            temp_cont2_list.append(thr_datas[j - 1])
        return show_contents2, num_list2, temp_cont2_list

    def get_sec_view_cont(self, thr_datas, in_seq):
        '''
        获取子二级展示数据信息，即向用户展示的第二级数据
        :param thr_datas:
        :param in_seq:
        :return:
        '''
        for rel in list(settings.rel_list.keys()):
            if in_seq == str(rel):
                show_contents2, num_list2, temp_cont2_list = self.handle_rela(in_seq, thr_datas)
                while True:
                    try:
                        in_seq2 = input('{}请输入要下载的图片风格对应的序号(q/Q退出): '.format(show_contents2)).strip()
                        if in_seq2.upper() == 'Q':
                            break
                            # continue
                        pic_name, pic_url = self.get_pic_nm_url(temp_cont2_list, in_seq2)
                        return (pic_name, pic_url, in_seq2)
                    except Exception as e:
                        print(e)

    def major(self, data_list):
        sec_datas, thr_datas = self.if_levl(data_list)
        show_contents1, num_list1 = self.get_fir_view_cont(sec_datas)
        while True:
            in_seq = input('{}请输入要下载的图片类型对应的序号(q/Q退出): '.format(show_contents1)).strip()
            if in_seq.upper() == 'Q':
                break
            if in_seq not in num_list1:
                print('您输入的序号不正确，请重新输入！！！')
            else:
                pic_infos = self.get_sec_view_cont(thr_datas, in_seq)
                if not pic_infos:
                    continue

                pblic = PublicBases()
                if pic_infos[2] == '26':
                    """ 性感美女 """
                    xinggan = XingGanGirls()
                    html = pblic.send(pic_infos[1])
                    # # # 单页下载
                    # xinggan.get_pics(html, pic_infos[0])
                    # 所有页下载
                    page_num = xinggan.get_page_num(html)
                    xinggan.more_pics_down(page_num, pic_infos[0], pic_infos[2])
                elif pic_infos[2] == '27':
                    """ 丝袜美女 """
                    siwa = SiWaGirls()
                    html = pblic.send(pic_infos[1])
                    # # 单页下载
                    # siwa.get_pics(html, pic_infos[0])
                    # 所有页下载
                    page_num = siwa.get_page_num(html)
                    siwa.more_pics_down(page_num, pic_infos[0], pic_infos[2])
                elif pic_infos[2] == '28':
                    """ 美女写真 """
                    xiezhen = MeiNvXieZhen()
                    html = pblic.send(pic_infos[1])
                    # # 单页下载
                    # xiezhen.get_pics(html, pic_infos[0])
                    # # 所有页下载
                    page_num = xiezhen.get_page_num(html)
                    xiezhen.more_pics_down(page_num, pic_infos[0], pic_infos[2])
                elif pic_infos[2] == '29':
                    """ 外国美女 """
                    waiguo = WaiGuoGirls()
                    html = pblic.send(pic_infos[1])
                    # 单页下载
                    waiguo.get_pics(html, pic_infos[0])
                    # # 所有页下载
                    # page_num = waiguo.get_page_num(html)
                    # waiguo.more_pics_down(page_num, pic_infos[0])
                elif pic_infos[2] == '30':
                    """ 内衣美女 """
                    nygirl = NeiYiGirls()
                    html = pblic.send(pic_infos[1])
                    # 单页下载
                    nygirl.get_pics(html, pic_infos[0])
                    # # 所有页下载
                    # page_num = nygirl.get_page_num(html)
                    # nygirl.more_pics_down(page_num, pic_infos[0])
                elif pic_infos[2] == '31':
                    """ 街拍美女 """
                    jiepai = JiePaiGirls()
                    html = pblic.send(pic_infos[1])
                    # 单页下载
                    jiepai.get_pics(html, pic_infos[0])
                    # # 所有页下载
                    # page_num = jiepai.get_page_num(html)
                    # jiepai.more_pics_down(page_num, pic_infos[0])
                elif pic_infos[2] == '32':
                    """ 美女自拍 """
                    zipai = ZiPaiGirls()
                    html = pblic.send(pic_infos[1])
                    # 单页下载
                    zipai.get_pics(html, pic_infos[0])
                    # # 所有页下载
                    # page_num = zipai.get_page_num(html)
                    # zipai.more_pics_down(page_num, pic_infos[0])
                elif pic_infos[2] == '33':
                    """ 人体艺术 """
                    yishu = BodyYiShu()
                    html = pblic.send(pic_infos[1])
                    # 单页下载
                    yishu.get_pics(html, pic_infos[0])
                    # # 所有页下载
                    # page_num = yishu.get_page_num(html)
                    # yishu.more_pics_down(page_num, pic_infos[0])
                elif pic_infos[2] == '34':
                    """ 美女模特 """
                    mote = GirlsModel()
                    html = pblic.send(pic_infos[1])
                    # 单页下载
                    mote.get_pics(html, pic_infos[0])
                    # # 所有页下载
                    # page_num = mote.get_page_num(html)
                    # mote.more_pics_down(page_num, pic_infos[0])
                else:
                    print('输入的号码有误，请重新输入！！！')
